<template>
	<view class="category-view-container">
		<!-- 自定义导航栏 -->
		<view class="custom-nav-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
			<view class="nav-content">
				<view class="nav-left">
					<text class="back-icon" @click="goBack">〈</text>
				</view>
				<view class="nav-title">
					<text class="title-text">{{categoryTitle}}</text>
				</view>
				<view class="nav-right">
					<view class="nav-actions">
						<text class="action-icon">...</text>
						<text class="action-icon">-</text>
						<text class="action-icon">○</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 商品列表 -->
		<view class="product-list">
			<view class="product-grid">
				<view 
					class="product-item" 
					v-for="(product, index) in products" 
					:key="index"
					@click="viewProduct(product)"
				>
					<view class="product-image">
						<image :src="product.image" mode="aspectFill" class="product-img"></image>
					</view>
					

					
					<view class="product-info">
						<text class="product-name">{{product.name}}</text>
						<view class="product-price">
							<text class="price-symbol">¥</text>
							<text class="price-value">{{product.price}}</text>
						</view>
						<view class="product-stats">
							<view class="stats-row">
								<text class="coupon-tag">券</text>
							</view>
							<view class="stats-row">
								<text class="sales-text">已售 {{product.sales}}</text>
								<text class="review-text">{{product.reviews}}条评论</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 0, // 状态栏高度
				categoryTitle: '新品推荐', // 分类标题
				categoryType: '', // 分类类型
				products: [
					{
						id: 1,
						name: '一加 OnePlus 9',
						price: '3799.00',
						sales: 0,
						reviews: 0,
						image: '/static/img/a.png',
						brand: 'HUAWEI',
						feature: ''
					},
					{
						id: 2,
						name: '华为笔记本MateBook',
						price: '2999.00',
						sales: 0,
						reviews: 0,
						image: '/static/img/a.png',
						brand: 'HUAWEI',
						feature: '全金属轻薄机身 多屏协同 指纹解锁'
					},
					{
						id: 3,
						name: '华为(HUAWEI)华为Mate 40',
						price: '4999.00',
						sales: 0,
						reviews: 0,
						image: '/static/img/a.png',
						brand: 'HUAWEI',
						feature: ''
					},
					{
						id: 4,
						name: '华为(HUAWEI) 华为畅享 20',
						price: '3999.00',
						sales: 2,
						reviews: 1,
						image: '/static/img/a.png',
						brand: 'HUAWEI',
						feature: ''
					},
					{
						id: 5,
						name: '小米 Redmi K30 至尊纪念版',
						price: '3000.00',
						sales: 2,
						reviews: 0,
						image: '/static/img/a.png',
						brand: 'XIAOMI',
						feature: ''
					},
					{
						id: 6,
						name: '朵唯(DOOV) X11Pro 安卓智能手机',
						price: '4542.00',
						sales: 2,
						reviews: 2,
						image: '/static/img/a.png',
						brand: 'DOOV',
						feature: ''
					}
				]
			}
		},
		onLoad(options) {
			// 获取状态栏高度
			this.getStatusBarHeight()
			
			// 获取传递的参数
			if (options.category) {
				this.categoryType = options.category
				this.setCategoryData(options.category)
			}
			
			// 获取商品列表
			this.getProducts()
		},
		methods: {
			// 获取状态栏高度
			getStatusBarHeight() {
				const systemInfo = uni.getSystemInfoSync()
				this.statusBarHeight = systemInfo.statusBarHeight
			},
			
			// 返回上一页
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			
			// 设置分类数据
			setCategoryData(category) {
				switch(category) {
					case 'new':
						this.categoryTitle = '新品推荐'
						break
					case 'headphone':
						this.categoryTitle = '潮流耳机'
						break
					case 'mobile':
						this.categoryTitle = '手机数码'
						break
					case 'computer':
						this.categoryTitle = '电脑办公'
						break
					default:
						this.categoryTitle = '新品推荐'
				}
			},
			
			// 获取商品列表
			getProducts() {
				// TODO: 调用后端接口获取商品列表
				// uni.request({
				// 	url: 'your-api-url/products',
				// 	method: 'GET',
				// 	data: { 
				// 		category: this.categoryType 
				// 	},
				// 	success: (res) => {
				// 		this.products = res.data
				// 	}
				// })
			},
			
			// 查看商品详情
			viewProduct(product) {
				// TODO: 跳转到商品详情页
				uni.showToast({
					title: `查看${product.name}`,
					icon: 'none'
				})
			}
		}
	}
</script>

<style scoped>
	.category-view-container {
		background-color: #f8f9fa;
		min-height: 100vh;
		padding-bottom: env(safe-area-inset-bottom);
	}

	/* 自定义导航栏样式 */
	.custom-nav-bar {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		background-color: #fff;
		z-index: 999;
		border-bottom: 1rpx solid #e8e8e8;
	}

	.nav-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		height: 88rpx;
	}

	.nav-left {
		display: flex;
		align-items: center;
	}

	.back-icon {
		font-size: 36rpx;
		color: #333;
		padding: 8rpx;
		border-radius: 50%;
		transition: background-color 0.2s ease;
	}

	.back-icon:active {
		background-color: #f0f0f0;
	}

	.nav-title {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.title-text {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
	}

	.nav-right {
		display: flex;
		align-items: center;
	}

	.nav-actions {
		display: flex;
		align-items: center;
	}

	.action-icon {
		font-size: 24rpx;
		color: #666;
		margin-left: 15rpx;
	}

	/* 商品列表 */
	.product-list {
		margin-top: 108rpx;
		padding: 20rpx;
	}

	.product-grid {
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		gap: 20rpx;
	}

	.product-item {
		background-color: #fff;
		border-radius: 12rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
		transition: all 0.2s ease;
	}

	.product-item:active {
		transform: scale(0.98);
		box-shadow: 0 1rpx 4rpx rgba(0, 0, 0, 0.12);
	}

	.product-image {
		width: 100%;
		height: 320rpx;
		position: relative;
		overflow: hidden;
	}

	.product-img {
		width: 100%;
		height: 100%;
		transition: transform 0.2s ease;
	}

	.product-item:active .product-img {
		transform: scale(1.05);
	}

	.product-info {
		padding: 20rpx;
	}

	.product-name {
		font-size: 28rpx;
		color: #333;
		line-height: 1.4;
		margin-bottom: 12rpx;
		font-weight: 500;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	.product-price {
		display: flex;
		align-items: baseline;
		margin-bottom: 12rpx;
	}

	.price-symbol {
		font-size: 24rpx;
		color: #ff4757;
		font-weight: 600;
		margin-right: 4rpx;
	}

	.price-value {
		font-size: 32rpx;
		color: #ff4757;
		font-weight: 600;
	}

	.product-stats {
		display: flex;
		flex-direction: column;
		gap: 8rpx;
	}

	.stats-row {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.coupon-tag {
		background-color: #ff4757;
		color: #fff;
		font-size: 20rpx;
		padding: 4rpx 8rpx;
		border-radius: 6rpx;
		font-weight: 500;
	}

	.sales-text, .review-text {
		font-size: 22rpx;
		color: #999;
	}

	/* 响应式适配 */
	@media screen and (max-width: 750rpx) {
		.product-grid {
			grid-template-columns: repeat(2, 1fr);
			gap: 15rpx;
		}
		
		.product-image {
			height: 280rpx;
		}
		
		.product-info {
			padding: 15rpx;
		}
		
		.product-name {
			font-size: 26rpx;
		}
		
		.price-value {
			font-size: 28rpx;
		}
	}

	@media screen and (max-width: 600rpx) {
		.product-list {
			padding: 15rpx;
		}
		
		.product-grid {
			gap: 12rpx;
		}
		
		.product-image {
			height: 240rpx;
		}
		
		.product-info {
			padding: 12rpx;
		}
		
		.product-name {
			font-size: 24rpx;
		}
		
		.price-value {
			font-size: 26rpx;
		}
	}
</style>
